package com.demodis.action;

import com.demodis.domain.Json;
import com.demodis.domain.TblGroup;
import com.demodis.service.GroupServiceI;
import com.demodis.service.impl.GroupServiceImpl;
import com.opensymphony.xwork2.ModelDriven;

public class GroupAction extends BaseAction implements ModelDriven<TblGroup>{

	private static final long serialVersionUID = 2456355156522960378L;

	TblGroup group = new TblGroup();
	
	GroupServiceI groupService = new GroupServiceImpl();
	
	public void query() {
		super.writeJson(groupService.getGroup(""));
	}
	
	// add by robbie
	public void queryAll() {
		super.writeJson(groupService.getGroup("a"));
	}
	
	
	public void add() {
		Json json = new Json();
		if(groupService.save(group)) {
	      json.setSuccess(true);
	      json.setMsg("添加成功!");
	    } else {
	      json.setMsg("添加失败!");
	    }

	    super.writeJson(json);
	}
	public void addScore() {
		Json json = new Json();
		if(groupService.saveScore(group)) {
			json.setSuccess(true);
			json.setMsg("录入成功!");
		} else {
			json.setMsg("录入失败!");
		}
		
		super.writeJson(json);
	}
	
	public void modify() {
		Json json = new Json();
		if(groupService.modify(group)) {
	      json.setSuccess(true);
	      json.setMsg("修改成功!");
	      json.setObject(group);
	    } else {
	      json.setMsg("修改失败!");
	    }

	    super.writeJson(json);
	}
	
	public void delete() {
		Json json = new Json();
		if(groupService.delete(group)) {
	      json.setSuccess(true);
	      json.setMsg("删除成功!");
	    } else {
	      json.setMsg("删除失败!");
	    }

	    super.writeJson(json);
	}
	
	public void getGroupComboBoxData() {
		 super.writeJson(groupService.getGroupComboBoxData());
	}
	
	@Override
	public TblGroup getModel() {
		// TODO Auto-generated method stub
		return group;
	}

}
